package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.atguigu.gmall.product.service.SkuManageService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping()
public class SkuManageController {
    @Autowired
    private SkuManageService skuManageService;

    /**
     * 保存spu
     * @param skuInfo
     * @return
     */
    @PostMapping("/admin/product/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        skuManageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }
    /**
     * 上架
     * @param skuId
     * @return
     */
    @GetMapping("/admin/product/onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){
        skuManageService.onSale(skuId);
        return Result.ok();
    }
    /**
     * 下架
     * @param skuId
     * @return
     */
    @GetMapping("/admin/product/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
       skuManageService.cancelSale(skuId);
        return Result.ok();
    }

    /**
     * 查询sku的分页信息
     * @param page
     * @param limit
     * @param category3Id
     * @return
     */
    @GetMapping("/admin/product/list/{page}/{limit}")
    public Result list(@PathVariable("page") Long page,@PathVariable("limit") Long limit,@RequestParam("category3Id")Long category3Id){
        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);
      skuInfoPage=  skuManageService.getPageSkuinfoList(skuInfoPage,category3Id);
      return Result.ok(skuInfoPage);
    }
}
